package com.itlin.handeinterview;

import java.math.BigDecimal;

/**
 * @author Lin
 * @date 2022/11/29 - 17:31
 * @description 水果实体类
 */
public class Fruit {
    // 水果名称
    private String Name;
    // 水果价格 斤
    private int price;
    // 重量 斤
    private int weight;
    // 折扣
    private double discount;
    // 总价
    private double sum;

    public Fruit(String name, int price, int weight, double discount) {
        Name = name;
        this.price = price;
        this.weight = weight;
        this.discount = discount;
    }

    public Fruit() {
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public double getDiscount() {
        return discount;
    }

    public void setDiscount(double discount) {
        this.discount = discount;
    }

    public double getSum() {
        //金额使用BigDecimal
        BigDecimal p1 = new BigDecimal(Double.toString(price*weight));
        BigDecimal p2 = new BigDecimal(Double.toString(discount));
        sum = p1.multiply(p2).doubleValue();
        return sum;
    }
}
